<?php
class IndexApp extends CommonApp {
   
    	/**
	 * 首页
	 */
	public function indexAct(){
		$type = C('type');
        $related = C('related');
        $company_type = C('company_type');
		//search
		$search = array();
		$search['where'] = "1 ";
		// $search['where'] .= "AND A.`item`='{$item}' ";
		//publish
		// if(My::arr2var($_GET,'publish')==='0'){
		// 	$search['where'] .= "AND publish=0 ";
		// }elseif(My::arr2var($_GET,'publish')==1){
		// 	$search['where'] .= "AND publish=1 ";
		// }
		//搜索毕业年份
		if(My::arr2var($_GET,'year')!=''){
			$year = I('get.year');
			$search['where'] .= "AND `year` = '{$year}' ";
		}
		//搜索专业
		if(My::arr2var($_GET,'major')!=''){
			$major = $_GET['major'];
			$search['where'] .= "AND `major` like '%{$major}%' ";
		}
		$search['page'] = My::arr2var($_REQUEST,'page').(isset($_SESSION['pagesize'])?$_SESSION['pagesize']:'');//用于参与缓存标识
		$search['pagesize'] = isset($_COOKIE['pagesize']) ? $_COOKIE['pagesize'] : '5';
		// $result=My::getCache($search,array('pre'=>'members'));
		// if($result==''){
			//page
		$count = DB('members')->where($search['where'])->count();
		$result['page'] = My::page($count,array('pagesize'=>$search['pagesize']));
		//result
		$result['data'] = DB('members')->where($search['where'])->limit($result['page']['limits'])->select();
		//echo DB('')->getLastSql();
		if(is_array($result['data']))
		foreach($result['data'] as &$value){
			$value['info'] = DB('info')->where("parent_id = '".$value['id']."'")->select();
			//获取年份
			$value['year'] = My::id2field('category',$value['year'],'title');
			//获取专业
			$value['major'] = My::id2field('category',$value['major'],'title');
			if(!empty($value['info'])){
				foreach ($value['info'] as &$value1) {
					$value1['province'] = M('Address')->getProvince($value1['province']);
					$value1['city'] = M('Address')->getProvince($value1['city']);
					$value1['type'] = $type[$value1['type']];
        			$value1['related'] = $related[$value1['related']];
        			$value1['company_type'] = $company_type[$value1['company_type']];
				}
			}
		}
		// 	My::setCache($search,$result,array('pre'=>'members'));
		// }
		$major = M('category')->item2submenu('class',array('level'=>'1'));
        $year = M('category')->item2submenu('year',array('level'=>'1'));
        $this->assign('major',$major);
        $this->assign('year',$year);
		$this->assign('result',$result);
		$this->display();
	}
   
}